public class Number {

    public static void rotate(int[] nums, int k) {
        int n = nums.length;
        int[] array = new int[n];
        for (int i = 0; i < n; i++) {
            array[(i+k) % n] = nums[i];
        }
        System.arraycopy(array, 0, nums, 0, n);
    }

    //给定一个整数数组 nums，将数组中的元素向右轮转 k 个位置，其中 k 是非负数
    public static void rotate1(int[] nums, int k) {
        int j1 = nums.length;
        int[] tmp = new int[j1];
        for (int i = 0; i < j1-k; i++) {
            tmp[i] = nums[i];
        }
        for (int i = 0; i < k; i++) {
            for (int j = j1-k-1+i; j >= 0 ; j--) {
                tmp[j+1] = tmp[j];
            }
        }
        for (int i = 0; i < k; i++) {
            tmp[k-i-1] = nums[j1-i-1];
        }

        for (int i = 0; i < j1; i++) {
            nums[i] = tmp[i];
        }

        for (int i: nums) {
            System.out.print(i+" ");
        }
    }

    public static void main(String[] args) {
        int[] nums = {1,2,3,4,5,6,7};
        int k = 3;
        rotate(nums,k);
    }

}
